package com.cloudxingkong.dianyinke.Student.Utils;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.PopupWindow;

import com.cloudxingkong.dianyinke.R;

/**
 * Created by ningfei on 2016/4/13.
 */
public class DDPopupWindowTwo extends PopupWindow {
    private View contentView;
    private Button btnZan,btnPingLun;
    private setOnClickPpWdListener onClickPpWdListener;
    public DDPopupWindowTwo(final Context context,setOnClickPpWdListener onClickPpWdListener) {
        super(context);
        LayoutInflater inflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        contentView=inflater.inflate(R.layout.layout_popupwindow,null);
        btnPingLun= (Button) contentView.findViewById(R.id.btn_pingluns);
        btnZan= (Button) contentView.findViewById(R.id.btn_zans);




        this.setContentView(contentView);
        this.setWidth(390);
        this.setHeight(70);
        this.setFocusable(true);
        this.setOutsideTouchable(true);

        this.update();
        this.setAnimationStyle(R.style.popupWindow);

        ColorDrawable dw=new ColorDrawable(0);
        this.setBackgroundDrawable(dw);

        onClickPpWdListener.onClickZan2(btnZan);
        onClickPpWdListener.onClickComment2(btnPingLun);

//        btnZan.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Toast.makeText(context, "赞", Toast.LENGTH_SHORT).show();
//
//            }
//        });
//        btnPingLun.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Toast.makeText(context,"评论",Toast.LENGTH_SHORT).show();
//
//
//            }
//        });
    }


    public void showPopupWindow(View parent) {
        if (!this.isShowing()) {
            View view=this.getContentView();
            view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
            Log.e("test", view.getMeasuredWidth() + " <getMeasuredWidth " + view.getWidth() + " <getWidth " + this.getWidth() + " <popupWindow.getWindow " + View.MeasureSpec.UNSPECIFIED);
            this.showAsDropDown(parent, parent.getWidth() - view.getMeasuredWidth()+90, -parent.getHeight()-10);
        }else{
            this.dismiss();
        }
    }

public interface setOnClickPpWdListener{
    void onClickZan2(View v);
    void onClickComment2(View v);
}
}
